<%--
  Created by IntelliJ IDEA.
  User: 王清华
  Date: 2018/4/30
  Time: 18:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="head" tagdir="/WEB-INF/tags/heads" %>
<%@ taglib prefix="foot" tagdir="/WEB-INF/tags/feet" %>
<html>
<head:html-heads pageTitle="测试页面"/>
<style>

    .window {
        width: 400px;
        position: absolute;
        margin-left: -200px;
        margin-top: -80px;
        top: 50%;
        left: 50%;
        display: block;
        background: #fff;
    }

</style>
<body style="background: #f1f1f1;">

<div class="window">

    <form class="layui-form" id="loginForm" method="post">
        <div class="layui-form-item" style="margin-right: 100px;margin-top: 20px;">
            <label class="layui-form-label">用户名：</label>
            <div class="layui-input-block">
                <input type="text" name="username" required lay-verify="required" placeholder="请输入用户名"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密&nbsp;&nbsp;&nbsp;&nbsp;码：</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div style="text-align: center;">
                <input type="button" id="submit" onclick="login()" class="layui-btn"
                       value="登&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;录"/>
                <input type="button" id="registered" class="layui-btn" value="注&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;册"/>
            </div>
        </div>
    </form>
</div>

<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;
    });

    function login() {
        var obj = $('#loginForm').serialize();
        $.ajax({
            type: "POST",
            url: "/api/system/login",
            data: obj,// 要提交的表单
            success: function (msg) {
                if (msg.code === 1) {
                    window.open('/test')
                } else {
                    layer.open({
                        type: 0,
                        title: '信息框',
                        shadeClose: true,
                        area: ['300px', '200px'],
                        content: '<h3>'+msg.message+'</h3>'
                    })
                }
            },
            error: function (error) {
                console.log(error)
            }
        });
    }

</script>
</body>
</html>
